package com.weic.easycache.receiver.storage;

import android.content.Context;
import android.content.Intent;

import com.weic.easycache.phone.Storage;
import com.weic.easycache.phone.Storage.SdCard;
import com.weic.easycache.receiver.CntObservable;
import com.weic.easycache.receiver.storage.StorageObservable.Data;

public class StorageObservable extends CntObservable<StorageObserver, Data> {
	static class Data {
		private Context context;
		private Intent intent;
		private String action;
		private String path;
		private SdCard sdcard;

		public Data(Context context, Intent intent) {
			this.context = context;
			this.intent = intent;
			action = intent.getAction();
			path = intent.getData() != null ? intent.getData().getPath() : null;
			sdcard = Storage.getSdCardByFilePath(path);
		}
	}

	@Override
	protected Data onParserData(Context context, Intent intent) {
		return new Data(context, intent);
	}

	@Override
	protected void onChange(StorageObserver observer, Data data) {
		observer.onChanged(data.context, data.intent, data.action, data.path, data.sdcard);
	}
}
